<template>
  <div class="loginContainer">
    <van-image
      class="img"
      round
      width="10rem"
      height="10rem"
      fit="contain"
      :src="userInfo.avatar"
    />
    <div class="userName">{{ userInfo.name }}</div>
    <van-button
      type="primary"
      class="btn"
      @click="sureLogin"
    >确定登录</van-button>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  name: 'home',
  data () {
    return {
      userInfo: {},
      params: {
        id: '',
        merchant_id: '',
        openid: ''
      }
    }
  },
  mounted () {
    this.params.merchant_id = this.$route.query.id
    this.params.id = this.$route.query.cid
    this.params.openid = localStorage.getItem('OPENID')
    this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
    console.log('123456789', this.userInfo)
  },
  methods: {
    sureLogin() {
      this.$request.loginM(this.params).then(res => {
        console.log(res)
        if(res.data.ret == 200) {
          Toast('登录成功')
          this.$router.replace('case')
        } else {
          Toast('登录失败')
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.loginContainer {
  display: flex;
  flex-direction: column;
  font-size: 1.2rem;
  margin-top: 5rem;
  align-items: center;
  .userName {
    margin-top: 5rem;
  }
  .btn {
    margin-top: 5rem;
  }
}
</style>